package homework5

import akka.actor.{Actor, ActorRef}

import scala.collection.mutable.Map

class MasterActor extends Actor {
  override def receive: Receive = {
    case ("注册", name: String, actorRef: ActorRef) => {
      MasterActor.map.put(name, System.currentTimeMillis())
      actorRef ! "注册成功"
    }
    case ("心跳", name: String, actorRef: ActorRef) => {
      if (MasterActor.map.contains(name)) {
        MasterActor.map.put(name, System.currentTimeMillis())
        actorRef ! System.currentTimeMillis()
      }

    }
  }

}

object MasterActor {
  val map = Map[String, Long]()
}
